<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %><%--
  Created by IntelliJ IDEA.
  User: zhli
  Date: 2020/4/9
  Time: 上午8:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

<%
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    String msg = "";
    String name = request.getParameter("name");
    String sex = request.getParameter("sex");
    String province = request.getParameter("province");
    String school = request.getParameter("school");
    if (name == null || "".equals(name)) {
        msg = "请填写姓名";
    } else if (school == null || "".equals(school)) {
        msg = "请填写报考的学校";
    }


    if ("".equals(msg)) {
        //统计信息
        Map<String, Integer> sexMap = new HashMap<>();
        Object sexO = application.getAttribute("sexMap");
        if (sexO == null) {
            sexMap.clear();
            sexMap.put("男", 0);
            sexMap.put("女", 0);
            application.setAttribute("sexMap", sexMap);
        }
        sexMap = (Map<String, Integer>) application.getAttribute("sexMap");
        int boyCount = sexMap.get("男");
        int girlCount = sexMap.get("女");
        if ("男".equals(sex)) {
            sexMap.put("男", ++boyCount);
        } else {
            sexMap.put("女", ++girlCount);
        }
        application.setAttribute("sexMap", sexMap);


        Map<String, Integer> provinceMap = new HashMap<>();
        Object provinceO = application.getAttribute("provinceMap");
        if (provinceO == null) {
            provinceMap.clear();
            provinceMap.put("宁夏", 0);
            provinceMap.put("其他", 0);
            application.setAttribute("provinceMap", provinceMap);
        }
        provinceMap = (Map<String, Integer>) application.getAttribute("provinceMap");
        int nxCount = provinceMap.get("宁夏");
        int qitaCount = provinceMap.get("其他");
        if ("宁夏".equals(province)) {
            provinceMap.put("宁夏", ++nxCount);
        } else {
            provinceMap.put("其他", ++qitaCount);
        }
        application.setAttribute("provinceMap", provinceMap);


        //跳转准考证页面
        request.setAttribute("examno", new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date()));
        request.setAttribute("name", name);
        request.setAttribute("sex", sex);
        request.setAttribute("province", province);
        request.setAttribute("school", school);
        request.getRequestDispatcher("success.jsp").forward(request, response);
    } else {
        request.setAttribute("msg", msg);
        request.setAttribute("name", name);
        request.setAttribute("school", school);
        request.getRequestDispatcher("index.jsp").forward(request, response);
    }
%>

</body>
</html>
